package cn.itcast.order;


import cn.itcast.feign.client.UserClient;
import cn.itcast.feign.config.DefaultFeignConfiguration;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

//开启Feign远程调用注解
@EnableFeignClients(clients = {UserClient.class} , defaultConfiguration = DefaultFeignConfiguration.class)
@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    @Bean
    //注册RestTemplate,在利用这个工具来向其他模块发起请求
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

//    @Bean
//    //自定义负载均衡规则为=随机,默认为=轮询调度,此处配置负载均衡规则为全局配置,无论访问任何服务模块都为当前负载均衡的配置
//    public IRule randomRule(){
//        return new RandomRule();
//    }

}